package com.sykj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.pojo.Review;
import com.sykj.servies.ProductServies;
import com.sykj.servies.ReviewService;
import com.sykj.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/review")
public class ReviewController {
    //评论表
    @Autowired
    ReviewService reviewService;
    @Autowired
    ProductServies productServies;
    @RequestMapping("/list")
    public String List(Model model, Page page){
        //分页查询
        PageHelper.offsetPage(page.getStart(),page.getCount());
        List<Review> list=reviewService.list();
        //总页数
        int total=(int)new PageInfo<>(list).getTotal();
        page.setTotal(total);
        model.addAttribute("totals",list.size());
        model.addAttribute("list",list);
        return  "pinglunpage/pinglun";
    }
    @RequestMapping("/del")
    public String del(int id){
        reviewService.del(id);
        return "redirect:list";
    }
}
